tests: Add a simple test-sysroot.js that covers OSTree.Sysroot
authorColin Walters <walters@verbum.org>
Wed, 2 Oct 2013 23:47:38 +0000 (19:47 -0400)
committerColin Walters <walters@verbum.org>
Thu, 3 Oct 2013 00:18:06 +0000 (20:18 -0400)
This will be more interesting as a test case user of the API.

Makefile-tests.am
tests/test-sysroot.js [new file with mode: 0644]

index c012141119a3430e44ab0d0228cec131e8177085..bfc84e49fc32dffa29c95e26e34145d8ccd5e91a 100644 (file)
@@ -57,7 +57,7 @@ gpginsttest_DATA = tests/gpghome/secring.gpg \
 
 %.test: tests/%.js Makefile
        $(AM_V_GEN) (echo '[Test]' > $@.tmp; \
-        echo 'Exec=$(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
+        echo 'Exec=env TESTDATADIR=$(pkglibexecdir)/installed-tests $(pkglibexecdir)/installed-tests/$(notdir $<)' >> $@.tmp; \
         echo 'Type=session' >> $@.tmp; \
         mv $@.tmp $@)
 
@@ -65,9 +65,10 @@ testmetadir = $(datadir)/installed-tests/$(PACKAGE)
 testmeta_DATA = $(testfiles:=.test)
 
 if BUILDOPT_GJS
-insttest_SCRIPTS += tests/test-core.js
-testmeta_DATA += test-core.test
+insttest_SCRIPTS += tests/test-core.js \
+       tests/test-sysroot.js \
+       $(NULL)
+testmeta_DATA += test-core.test test-sysroot.test
 endif
 
-
 endif
diff --git a/tests/test-sysroot.js b/tests/test-sysroot.js
new file mode 100644 (file)
index 0000000..ef1f26b
--- /dev/null
@@ -0,0 +1,53 @@
+#!/usr/bin/env gjs
+//
+// Copyright (C) 2013 Colin Walters <walters@verbum.org>
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the
+// Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+// Boston, MA 02111-1307, USA.
+
+const GLib = imports.gi.GLib;
+const Gio = imports.gi.Gio;
+
+const OSTree = imports.gi.OSTree;
+
+function assertEquals(a, b) {
+    if (a != b)
+       throw new Error("assertion failed " + JSON.stringify(a) + " == " + JSON.stringify(b));
+}
+
+function libtestExec(shellCode) {
+    let testdatadir = GLib.getenv("TESTDATADIR");
+    let libtestPath = GLib.build_filenamev([testdatadir, 'libtest.sh'])
+    let cmdline = 'bash -c ' + GLib.shell_quote('. ' + GLib.shell_quote(libtestPath) + '; ' + shellCode);
+    print("shellcode=" +cmdline);
+    let [,stdout,stderr,estatus] = GLib.spawn_command_line_sync(cmdline);
+    print(stderr);
+    GLib.spawn_check_exit_status(estatus);
+}
+
+libtestExec('setup_os_repository archive-z2 syslinux');
+
+let upstreamRepo = OSTree.Repo.new(Gio.File.new_for_path('testos-repo'));
+upstreamRepo.open(null);
+
+let [,rev] = upstreamRepo.resolve_rev('testos/buildmaster/x86_64-runtime', false);
+
+print("testos => " + rev);
+
+let sysroot = OSTree.Sysroot.new(Gio.File.new_for_path('sysroot'));
+sysroot.load(null);
+let deployments = sysroot.get_deployments();
+assertEquals(deployments.length, 0);
+